#pragma once

# include "MathFunc.h"
# include <vector>

using namespace MathFunction;
using namespace std;

namespace TryWF {

	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;

	/// <summary>
	/// Summary for MyForm
	/// </summary>
	public ref class MyForm : public System::Windows::Forms::Form
	{
	public:
		MyForm(void)
		{
			InitializeComponent();
			//
			//TODO: Add the constructor code here
			//
		}

	protected:
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		~MyForm()
		{
			if (components)
			{
				delete components;
			}
		}
	private: System::Windows::Forms::TextBox^  displayBox;
	private: System::Windows::Forms::Button^  ok;
	private: System::Windows::Forms::TextBox^  inputBox;
	private: System::Windows::Forms::Label^  label1;
	private: System::Windows::Forms::Label^  label2;
	private: System::Windows::Forms::Button^  hello;



	protected: 


	protected: 

	private:
		/// <summary>
		/// Required designer variable.
		/// </summary>
		System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		void InitializeComponent(void)
		{
			this->displayBox = (gcnew System::Windows::Forms::TextBox());
			this->ok = (gcnew System::Windows::Forms::Button());
			this->inputBox = (gcnew System::Windows::Forms::TextBox());
			this->label1 = (gcnew System::Windows::Forms::Label());
			this->label2 = (gcnew System::Windows::Forms::Label());
			this->hello = (gcnew System::Windows::Forms::Button());
			this->SuspendLayout();
			// 
			// displayBox
			// 
			this->displayBox->BackColor = System::Drawing::SystemColors::ControlLightLight;
			this->displayBox->Location = System::Drawing::Point(12, 33);
			this->displayBox->Multiline = true;
			this->displayBox->Name = L"displayBox";
			this->displayBox->ReadOnly = true;
			this->displayBox->ScrollBars = System::Windows::Forms::ScrollBars::Vertical;
			this->displayBox->Size = System::Drawing::Size(260, 103);
			this->displayBox->TabIndex = 1;
			this->displayBox->Text = L"Your results will be displayed here...";
			// 
			// ok
			// 
			this->ok->Location = System::Drawing::Point(197, 152);
			this->ok->Name = L"ok";
			this->ok->Size = System::Drawing::Size(75, 23);
			this->ok->TabIndex = 1;
			this->ok->Text = L"Generate";
			this->ok->UseVisualStyleBackColor = true;
			this->ok->Click += gcnew System::EventHandler(this, &MyForm::ok_Click);
			// 
			// inputBox
			// 
			this->inputBox->Location = System::Drawing::Point(12, 154);
			this->inputBox->Name = L"inputBox";
			this->inputBox->Size = System::Drawing::Size(100, 21);
			this->inputBox->TabIndex = 0;
			// 
			// label1
			// 
			this->label1->AutoSize = true;
			this->label1->Location = System::Drawing::Point(12, 139);
			this->label1->Name = L"label1";
			this->label1->Size = System::Drawing::Size(167, 12);
			this->label1->TabIndex = 3;
			this->label1->Text = L"Enter your upper bound here";
			// 
			// label2
			// 
			this->label2->AutoSize = true;
			this->label2->Location = System::Drawing::Point(12, 18);
			this->label2->Name = L"label2";
			this->label2->Size = System::Drawing::Size(197, 12);
			this->label2->TabIndex = 4;
			this->label2->Text = L"Primes less than the upper bound";
			// 
			// hello
			// 
			this->hello->Location = System::Drawing::Point(164, 212);
			this->hello->Name = L"hello";
			this->hello->Size = System::Drawing::Size(75, 23);
			this->hello->TabIndex = 5;
			this->hello->Text = L"hello";
			this->hello->UseVisualStyleBackColor = true;
			this->hello->Click += gcnew System::EventHandler(this, &MyForm::hello_Click);
			// 
			// MyForm
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 12);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->ClientSize = System::Drawing::Size(289, 254);
			this->Controls->Add(this->hello);
			this->Controls->Add(this->label2);
			this->Controls->Add(this->label1);
			this->Controls->Add(this->inputBox);
			this->Controls->Add(this->ok);
			this->Controls->Add(this->displayBox);
			this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::FixedSingle;
			this->MaximizeBox = false;
			this->Name = L"MyForm";
			this->Text = L"Prime Gen";
			this->ResumeLayout(false);
			this->PerformLayout();

		}
#pragma endregion
	private: System::Void ok_Click(System::Object^  sender, System::EventArgs^  e) {
				 try
				 {
					 int p = int::Parse(inputBox->Text);

					 Prime prime(p);

					 std::vector<int> primeList = prime.GetPrimeList();
					 String^ s = "";
					 int totalPrime = (int)primeList.size();

					 for (int i = 0; i < totalPrime; i ++)
					 {
						 s = s + primeList[i].ToString();
						 if (i != totalPrime - 1)
						 {
							 s = s + ", ";
						 }
					 }

					 if (totalPrime != 0)
					 {
						 displayBox->Text = s;
					 } else
					 {
						 displayBox->Text = "None Primes are found...";
					 }
				 } catch (std::exception e)
				 {
					 // Convert from unmanaged string to managed String.
					 //String^ ex = gcnew String(e.c_str());

					 MessageBox::Show("Non-negative integer required.");
				 } catch (System::FormatException^ e)
				 {
					 MessageBox::Show("Input format error");
				 }
			 }

private: System::Void hello_Click(System::Object^  sender, System::EventArgs^  e) {
		 }
};
}
